<div class="top">
	<div class="left">
		<a href="m.admin-login.html"><i class="icon-tag"></i></a>
		<a href="m.main.html">首页</a>
	</div>
	<div class="right">
        {{#if loginer}}
        <a href="m.cart.html" class="bar-button icon-cart">购物车</a>
		<a id="loginer_info" class="bar-button icon-user" href="./m.personal.html">{{loginer.info.name}}</a>
        <a event-click="{{'$Event.user_login_out'}}" id="login_out" href="#">注销</a>
		{{#else}}
            {{#if $Cache._in_sign_in_or_up}}
            {{#else}}
            <a id="sign_in_btn" href="m.login.html?id=1" class="bar-button border icon-user">登陆</a>
            <a id="sign_up_btn" href="m.login.html?id=2" class="bar-button icon-pencil">注册</a>
            {{/if}}
        {{/if}}
	</div>
</div>
<div class="block"></div>


<div class="blockwrap"></div>
<script type="text/vm">
function(vm) {
    require(["core"], function(jSouper) {
        jSouper.ready(function() {
            App.set("$Event.user_login_out", function() {
                require(["Cookies"], function(Cookies) {
                    Cookies.set("loginSession", "");
                });
                App.set("loginer", null);
            });
        });
    });
    require(["common", "coAjax", "href", "eventManager"], function(jSouper, coAjax, href, eventManager) {
        var sign_in_btn_node = vm.queryElement({
            id: "sign_in_btn"
        })[0];
        var sign_up_btn_node = vm.queryElement({
            id: "sign_up_btn"
        })[0];
        var login_out_btn_node = vm.queryElement({
            id: "login_out"
        })[0];
        if (location.pathname !== "/m.login.html" || location.pathname !== "/m.login.html") {
            var cb_url = "&cb_url=" + encodeURIComponent(location.href);
            sign_in_btn_node.href += cb_url;
            sign_up_btn_node.href += cb_url;
        } else {
            App.set("$Cache._in_sign_in_or_up", true);
        }
        //callback功能
        if (location.pathname !== "/sign_in.html") {
            var cb_url = "&cb_url=" + encodeURIComponent(location.href);
            App.set("$Cache.cb_url", cb_url);
        } else {
            App.set("$Cache._in_sign_in_or_up", true);
        }
        //注销功能
        App.set("$Event.user_login_out", function() {
            coAjax.get(appConfig.user.login_out_url, function() {
                App.set("loginer", null);
                if (href.isUser()) {
                    href.toLogin();
                }
            });
        });

        //获取登陆用户的信息
        /*
         * 管理员相关的页面无需登录
         */
        var no_user_login_pages = {
            "/m.admin.html": 1,
            "/m.admin-login.html": 1
        }
        if (no_user_login_pages[location.pathname]) {
            App.set("$Cache.is_in_admin", true);
            return;
        }
        console.log("获取登陆者信息……", location.pathname);
        /*
         * 获取登录者信息
         */
        function _check_collect_bus(collectBus) {
            var is_collect = true;
            if (jSouper.indexOf(collectBus, appConfig.bus_id) === -1) {
                is_collect = false;
            }
            App.set("$Cache.is_collect_current_bus", is_collect)
        }
        coAjax.get(appConfig.user.loginer, function(data) {
            console.log("登录者信息：", data.result);
            userInfo = data.result;
            App.set("loginer", userInfo);
            //触发相关事件
            eventManager.fire("getLoginer");
        }, function(errorCode) {
            var muse_login_pages = {
                    "/m.personal.html": 1,
                    "/m.cart.html": 1
                }
                //未登录，不可进入个人页，强制跳转到登录页
            if (muse_login_pages[location.pathname]) {
                href.toLogin();
            }
            //触发相关事件
            eventManager.reject("getLoginer");
        });

    });



}
</script>